package com.shop.service.impl;

import com.github.pagehelper.PageInfo;
import com.shop.entity.Category;
import com.shop.mapper.CategoryMapper;
import com.shop.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("categoryService")
@RequiredArgsConstructor
@Transactional(rollbackFor = RuntimeException.class,
        propagation = Propagation.REQUIRED)
public class CategoryServiceImpl implements CategoryService {
    private final CategoryMapper categoryMapper;
    /**
     * 获取所有分类
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Category> listCategory(Integer pageNum, Integer pageSize) {
        List<Category> listCategory = categoryMapper.listCategory(pageNum, pageSize);
        return new PageInfo<>(listCategory);
    }

    @Override
    public Category getCategory(String name) {
        return categoryMapper.getCategory(name);
    }

    @Override
    public Category getCategoryById(Integer id) {
        return categoryMapper.getCategoryById(id);
    }

    @Override
    public void addCategory(Category category) {
        categoryMapper.addCategory(category);
    }

    @Override
    public void deleteCategory(Integer id) {
        categoryMapper.deleteCategory(id);
    }

    @Override
    public void updateCategory(Category category) {
        categoryMapper.updateCategory(category);
    }

    @Override
    public int getTotal() {
        return categoryMapper.getTotal();
    }
}
